package cn.com.ejiakanghu.dto;

import org.linlinjava.litemall.db.domain.LitemallGoodsSpecification;

import java.util.ArrayList;
import java.util.List;

public class GoodsSpecDataInfo {

    /**
     * 规格分类ID，唯一
     */
    private int id;

    /**
     * 规格分类名称，例如：颜色、尺寸、套餐
     */
    private String name;

    /**
     * 规格分类说明，例如：请选择您喜欢的颜色
     */
    private String desc;

    /**
     * 规格选项列表
     */
    private List<GoodsSpecItemInfo> list;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public List<GoodsSpecItemInfo> getList() {
        return list;
    }

    public void setList(List<GoodsSpecItemInfo> list) {
        this.list = list;
    }

    public static GoodsSpecDataInfo getInstance(String specification, List<LitemallGoodsSpecification> goodsSpecList) {
        if (goodsSpecList.size() == 0) {
            return null;
        }
        GoodsSpecDataInfo dataInfo = new GoodsSpecDataInfo();
        dataInfo.setName(specification);
        dataInfo.setDesc("");
        dataInfo.setId(0);
        List<GoodsSpecItemInfo> list = new ArrayList<>();
        goodsSpecList.stream().forEach(s -> {
            list.add(GoodsSpecItemInfo.getInstance(s));
        });
        dataInfo.setList(list);
        return dataInfo;
    }
}
